<!DOCTYPE html>
<html lang="zh-CN">
<style type="text/css">
    .title4 {
        color: #fafafa;

        letter-spacing: 0;

        font-size: 50px;

        text-shadow: 0px 1px 0px #999, 0px 2px 0px #888, 0px 3px 0px #777, 0px 4px 0px #666, 0px 5px 0px #555, 0px 6px 0px #444, 0px 7px 0px #333, 0px 8px 7px #001135;

    }

    .box {
        background-color: #FFF;
        border-radius: 5px;
        border: 1px solid #DDD;
        padding: 30px 20px;
        margin: 50px 10% 20px 10%;
        width: 80%;
        height: 400px;
        text-align: center;

    }

    .box:hover {
        box-shadow: 0 0 5px 3px #CCC;
    }

    .table11_7 table {
        width: 100%;
        margin: 15px 0;
        border: 0;
    }

    .table11_7 th {
        background-color: #00A5FF;
        color: #FFFFFF
    }

    .table11_7,
    .table11_7 th,
    .table11_7 td {
        font-size: 0.95em;
        text-align: center;
        padding: 4px;
        border-collapse: collapse;
    }

    .table11_7 th,
    .table11_7 td {
        border: 1px solid #2087fe;
        border-width: 1px 0 1px 0;
        border: 2px inset #ffffff;
    }

    .table11_7 tr {
        border: 1px solid #ffffff;
    }

    .table11_7 tr:nth-child(odd) {
        background-color: #aae1fe;
    }

    .table11_7 tr:nth-child(even) {
        background-color: #ffffff;
    }
</style>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>新闻类别信息</title>

    <link rel="stylesheet" href="../../Public/Css/index.css">
</head>

<body>
    <nav class="navbar">
        <div class="container navbar-content">
            <ul id="menu">
                <li>
                    <a href=""> 首页</a>
                </li>
                <li>
                    <a href=""> 排行</a>
                </li>
                <li>
                    <a href=""> 分类浏览</a>
                </li>
                <li>
                    <a href=""> 所有新闻</a>
                </li>
                <li>
                    <a href=""> 所有新闻</a>
                </li>
        </div><!-- /.container-fluid -->
    </nav>
    <h1 align="center" class="title4">新闻发布系统</h1>
    <form action="./Search_C.php" method="POST">
        <div class="box">
            <h2>新闻类别搜索结果</h2>


<?php
if ($_POST) {
    include_once("../../Functions/connectDatabase.php");
    get_connection();
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        if (empty($_POST["name"])) {
            echo "<script>alert('输入的新闻类别名称不能为空！');
            window.location.href = document.referrer;
        </script>";
        } else {
            $name = $_POST["name"];
            $sql = "SELECT * FROM category WHERE category_name='$name'";
            $result = mysqli_query($conn, $sql);
            if ($result->num_rows > 0) {
                while ($row = mysqli_fetch_assoc($result)) {
                    echo "名称：" . $row["category_name"] . "<br><br>";
                    $id = $row["category_id"];
                    $sql = "SELECT * FROM news WHERE category_id = $id";
                    $re = mysqli_query($conn, $sql);
                    echo "该类别下的新闻数：" . $re->num_rows . "（不为0时无法删除）<br><br>";
                    //管理员版，后续加入普通用户的
                    echo "<a href=\"../News/adminCategory.php?id=" . $row["category_id"] . "\">点击->前往该类别的新闻管理页面</a><br><br>";
                    echo "<a href=\"./Modify_V.php?id=" . $row["category_id"] . "&name=" . $row["category_name"] . "\">修改</a><br><br>";
                    echo "<a href=\"./Delete_V.php?id=" . $row["category_id"] . "&name=" . $row["category_name"] . "\">删除</a><br><br>";
                }
            } else {
                echo "搜索结果中没有名称为 $name 的新闻类型";
            }
        }
    }
    close_connection();
}
?>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <br><br><button type="button" onclick="javascript:history.back(-1);">返回上一页</button>
        </div>
</body>


</html>